package com.mentaleye.service.impl;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.dal.dao.PromptDao;
import com.mentaleye.dal.model.Dictionary;
import com.mentaleye.dal.model.Prompt;
import com.mentaleye.enums.CommonStatus;
import com.mentaleye.enums.DictionaryEnums;
import com.mentaleye.service.DictionaryService;
import com.mentaleye.service.PromptService;

@Service
public class PromptServiceImpl implements PromptService {
	@Autowired
	private PromptDao promptDao;
	private DictionaryService dictionaryService;
	
	@Override
	public List<Map<String, Object>> queryPromptByTypeAndPerson(List<Integer> promptRoles, String promptPersonId,
			Map<String, Object> map) {
		//Map<String, Object> map = new HashMap<String, Object>();
		Date date = new Date();
		DateFormat df1 = DateFormat.getDateInstance();// 日期格式，精确到日
		map.put("list", promptRoles);
		map.put("promptPersonId", promptPersonId);
		map.put("nowDate", df1.format(date));
		List<Map<String, Object>> list = promptDao.selectPromptByTypeAndPerson(map);
		return list;
	}

	@Override
	public List<Map<String, Object>> queryPromptCount(List<Integer> promptRoles, String promptPersonId) {
		Map<String, Object> map = new HashMap<String,Object>();
		Date date = new Date();
		DateFormat df1 = DateFormat.getDateInstance();// 日期格式，精确到日
		map.put("list", promptRoles);
		map.put("promptPersonId", promptPersonId);
		map.put("nowDate", df1.format(date));
		List<Map<String, Object>> list = promptDao.selectCountWithNoRead(map);
		return list;
	}

	@Override
	public boolean promptSave(String promptContext, Date endDate, String promptRoleId, String promptPersonId,
			CommonStatus commonStatus) {
		Prompt prompt = new Prompt();
		Integer value=DictionaryEnums.PROMPT_TIME.getCode();
		/*Dictionary dictionary = dictionaryService.queryDictionaryById(value);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(endDate);
		calendar.add(Calendar.DAY_OF_MONTH, Integer.parseInt(dictionary.getDictionaryValue()));
		prompt.setBeginDate(calendar.getTime());*/
		prompt.setEndDate(endDate);
		prompt.setIsAllPerson(0);
		prompt.setPromptContext(promptContext);
		prompt.setPromptPersonId(promptPersonId);
		prompt.setPromptRoleId(promptRoleId);
		prompt.setPromptType(commonStatus.getCode());
		boolean result = promptDao.insertPrompt(prompt);
		return result;

	}

	@Override
	public boolean promptSave(String promptContext, Date endDate, CommonStatus commonStatus) {
		Prompt prompt = new Prompt();
		Dictionary dictionary = dictionaryService.queryDictionaryById(DictionaryEnums.PROMPT_TIME.getCode());
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(endDate);
		calendar.add(Calendar.DAY_OF_MONTH, Integer.parseInt(dictionary.getDictionaryValue()));
		prompt.setBeginDate(calendar.getTime());
		prompt.setEndDate(endDate);
		prompt.setIsAllPerson(1);//提醒所有人
		prompt.setPromptContext(promptContext);
		prompt.setPromptType(commonStatus.getCode());
		boolean result = promptDao.insertPrompt(prompt);
		return result;
	}

	@Override
	public boolean promptSave(int classId, Prompt prompt, CommonStatus commonStatus) {
		// TODO Auto-generated method stub
		return false;
	}

}
